package cn.adelyn.blog.blogmanager.service;

import cn.adelyn.base.api.snowfalke.feign.SnowflakeFeignClient;
import cn.adelyn.blog.blogmanager.dao.TagDAOService;
import cn.adelyn.blog.blogmanager.pojo.model.TagModel;
import cn.adelyn.blog.blogmanager.pojo.vo.TagVO;
import cn.adelyn.common.core.pojo.vo.PageVO;
import cn.adelyn.common.database.pojo.dto.PageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TagService {

    @Autowired
    TagDAOService tagDAOService;

    @Autowired
    SnowflakeFeignClient snowflakeFeignClient;

    public void insertTag(String tagName, long userId) {
        TagModel tagModel = new TagModel();
        tagModel.setTagId(snowflakeFeignClient.snowflakeId().getData());
        tagModel.setTagName(tagName);
        tagModel.setUserId(userId);

        tagDAOService.insertTag(tagModel);
    }

    public void deleteTag(Long tagId) {
        tagDAOService.deleteTag(tagId);
    }

    public void updateTag(Long tagId, String tagName) {
        TagModel tagModel = new TagModel();
        tagModel.setTagId(tagId);
        tagModel.setTagName(tagName);

        tagDAOService.updateTag(tagModel);
    }

    public PageVO<TagVO> getTagPage(long userId, PageDTO pageDTO) {
        return tagDAOService.getTagPage(userId, pageDTO);
    }
}
